<?php
/**
 * Accessed from view.php. This permanently deletes all items marked as deleted
 * for a particular resourcepage.
 * @copyright &copy; 2006 The Open University
 * @author s.marshall@open.ac.uk
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package resourcepage
 *//** */
  
require_once("module_resourcepage.php");
$module=module_resourcepage::$inst;
 
$id=required_param('id',PARAM_INT);    // Course Module ID
$scrollpos=optional_param('scrollpos',0,PARAM_INT);

// Basic security checks
$module->obtain_view_info($id,null,$cm,$course,$resourcepage);
$module->verify_edit_action($cm);

// Get items to delete
$content=$module->get_container_items($resourcepage->deletedcontainerid);

$tw=new transaction_wrapper();
for($i=0;$i<$content[0]->get_child_count();$i++) {
    $thing=$content[0]->get_child($i);
    if(is_a($thing,'resourcepage_container')) {
        if($thing->get_resourcepage_id()==$resourcepage->id) {
            $module->delete_container_with_items($thing->get_container());
        } else {
            $module->delete_container_subcontainer(
                $resourcepage->deletedcontainerid,$thing->get_container());
        }
    } else {
        $module->delete_item($thing->get_item());
    }
}
$tw->commit();
 
// Log and return to view
add_to_log($course->id, "resourcepage", "containeritem", "view.php?id=$cm->id",
    "Cleared deleted items ($i items)",$cm->id);
redirect('view.php?id='.$cm->id.($scrollpos ? '&scrollpos='.$scrollpos : ''));
 
?>